#include <iostream>
using namespace std;
int gcd(int n,int m)
{
	return n%m == 0 ? m : gcd(m,n%m);
}
int main()
{
	int p, q;
	while(cin>>p>>q)
	{
		cout << p + q - gcd(p, q) << endl;
	}
	return 0;
}